<template>
    <div class="content">
      <div class="title">
        <i class="el-icon-setting"></i>
        <span style="font-weight: 400;color:#606266;cursor: text;margin-left:5px;">设备管理</span>
      </div>
      <div class="tables">
        <AssetlistHead></AssetlistHead>
        <!-- table表格：展示用户信息的地方 -->
        <el-table
          border
          stripe
          v-loading="listLoading"
          :data="assets"
          @selection-change="handleSelectionChange">

          <el-table-column
            type="selection"
            width="55" />

          <el-table-column
            type="index"
            label="id"
            width="80"
            align="center"
          />
          <el-table-column prop="serial_no" label="序列号"  />
          <el-table-column prop="brand" label="品牌" />
          <el-table-column prop="model" label="型号" />
          <el-table-column prop="assets_name" label="固定资产名称" />
          <el-table-column prop="assets_no" label="资产编号"/>
          <el-table-column prop="assets_dep_name" label="资产所在科室"/>
          <el-table-column prop="assets_time" label="注册时间"/>
          <el-table-column prop="assets_time" label="报废时间"/>
          <el-table-column prop="assets_type_name" label="固定资产类型 "/>
          <el-table-column prop="other" label="备注"/>
          <el-table-column label="操作" width="230" align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" icon="el-icon-view" title="查看配置"
                @click="ViewConfig(scope.row)"/>
              <el-button type="primary" size="mini" icon="el-icon-setting" title="编辑设备"
                @click="UpdateAsset(scope.row)"/>
              <el-button type="primary" size="mini" icon="el-icon-edit-outline" title="编辑设备"
                @click="UpKeep(scope.row)"/>
              <el-popconfirm :title="`确定报废吗?`" @onConfirm="scrapAsset(scope.row.id)">
                <el-button style="margin-left:10px" slot="reference" type="danger" size="mini" icon="el-icon-delete" 
                  title="报废资产"/>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <!-- table表格：展示用户信息的地方 -->
        <el-row style="margin-top:5px"> 
          <el-col :span="8">
            <el-button type="primary" size="small" title="增加设备" icon="el-icon-plus" @click="Add_Asset()">增加设备</el-button>
            <el-button type="primary" size="small" title="打印条码" icon="el-icon-camera" >打印条码</el-button>
            <el-button type="danger" size="small" title="删除选中" icon="el-icon-delete" >删除选中</el-button>
            <el-button type="danger" size="small" title="作废选中" icon="el-icon-delete-solid" >作废选中</el-button>
          </el-col>
            <!--分页器-->
          <el-col :span="16">
            <el-pagination
                
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="page_info.currentPage"
                :page-size="20"
                layout="total, prev, pager, next"
                :total="page_info.total"
                >
            </el-pagination> 
          </el-col>
        </el-row>
        <!--分页器-->
        <!-------对话框部分--->
        <!--设置配置-->
        <el-dialog title="设备配置" :visible.sync="configDialog"  v-if="configDialog"> 
          <ViewConfigDialog :AssetId="this.asset"></ViewConfigDialog>
        </el-dialog>

        <!--修改设备信息-->
        <el-dialog title="修改设备" v-if="setDialog"
        :before-close="handleClose" 
        :visible.sync="setDialog"
        :close-on-click-modal="false">
          <UpdateAssetDialog  :Asset="this.asset"></UpdateAssetDialog>
        </el-dialog>

        <!--增加设备信息-->
        <el-dialog title="修改设备" v-if="addDialog"
        :before-close="handleClose" 
        :visible.sync="addDialog"
        :close-on-click-modal="false">
          <UpdateAssetDialog :Asset="this.asset"></UpdateAssetDialog>
        </el-dialog>
      </div>
    </div>
</template>
<script>
import ViewConfigDialog from "../dialogs/ViewConfigDialog.vue";
import UpdateAssetDialog from "../dialogs/UpdateAssetDialog.vue"
import AssetlistHead from "./AssetslistHead.vue"
export default {
    name:"Assetslist",
    data() {
        return {
          listLoading: false, // 是否显示列表加载的提示
          page_info:{
            total:1000,
            currentPage:2
          },//封装分页信息
          assets:[],//选中的列表
          asset:"",//当前要操作的装备对象
          configDialog:false,//查看配置弹窗组件
          setDialog:false, //设置配置弹窗组件
          addDialog:false//增加设备的弹窗组件
        }
  },
  methods:{
    //打开配置页面
    ViewConfig(row){
      this.asset=row;
      this.configDialog=true;
    },
    //打开编辑页面
    UpdateAsset(row){
      this.asset=row;
      this.setDialog=true;
      
    },
    //打开维护页面
    UpKeep(row){
      console.log(row);
    },
    handleClose(done){
      this.$confirm('是否不保存就关了吗？？').then(()=>{
            this.setDialog=false;
            this.addDialog=false;
            done();
          }).catch(()=>{});
      
    },
    //关闭对话框
    closeSetDialog(){
      this.setDialog=false;
      this.addDialog=false;
    },
    Add_Asset(){
      this.addDialog=true;
      this.asset={
                id:"",
                serial_no:"",
                brand:"",
                model:"",
                assets_name:"",
                simple_name:"",
                assets_no:"",
                assets_dep:"",
                assets_dep_name:"",
                assets_user:"",
                assets_user_name:"",
                assets_manage_dep:"",
                assets_manage_depN:"",
                assets_company:"",
                use_location:"",
                assets_time:"",
                assets_reg:"",
                assets_reg_name:"",
                scrap_time:"",
                scrap_user:"",
                scrap_user_name:"",
                assets_type:"",
                assets_type_name:"",
                other:""
            }
    },
    handleSelectionChange(){

    },
    handleSizeChange(){

    },
    handleCurrentChange(){

    },
    removeAsset(){

    },
    scrapAsset(){

    },
    Search(){
        //通过ajax请求获取查询结果
    }
    
  },
  components:{
    ViewConfigDialog,
    UpdateAssetDialog,
    AssetlistHead
  },
  mounted(){
    this.$bus.$on("closeSetDialog",this.closeSetDialog);
    this.$bus.$on("Search",this.Search);
    this.$store.dispatch("Get_dep_options");
    this.$store.dispatch("Get_type_options");
    //通过ajax请求初始化列表。
    this.assets=[
           {
                id:"01",
                serial_no:"asdffdsa",
                brand:"惠普",
                model:"chengming",
                assets_name:"惠普笔记本电脑",
                simple_name:"hpbjbdn",
                assets_no:"TY000001",
                assets_dep:"01",
                assets_dep_name:"信息科",
                assets_user:"01",
                assets_user_name:"张三",
                assets_manage_dep:"01",
                assets_manage_depN:"信息科",
                assets_company:"翰林科技",
                use_location:"3楼妇科病区",
                assets_time:"2020-01-01",
                assets_reg:"01",
                assets_reg_name:"张三",
                scrap_time:"2020-01-01",
                scrap_user:"01",
                scrap_user_name:"张三",
                assets_type:"01",
                assets_type_name:"笔记本",
                other:"演示数据，用于描述"
            },
            {
                id:"02",
                serial_no:"asdffdsa",
                brand:"惠普",
                model:"HP",
                assets_name:"惠普笔记本电脑",
                simple_name:"hpbjbdn",
                assets_no:"TY000001",
                assets_dep:"01",
                assets_dep_name:"信息科",
                assets_user:"01",
                assets_user_name:"张三",
                assets_manage_dep:"01",
                assets_manage_depN:"信息科",
                assets_company:"翰林科技",
                use_location:"3楼妇科病区",
                assets_time:"2020-01-01",
                assets_reg:"01",
                assets_reg_name:"张三",
                scrap_time:"2020-01-01",
                scrap_user:"01",
                scrap_user_name:"张三",
                assets_type:"01",
                assets_type_name:"笔记本",
                other:"演示数据，用于描述"
            }
]
  }
}
</script>
<style scoped>
  .title{
    margin-top:10px;
    margin-left:20px;
    font-size: 15px;
  }
  .content{
    text-align: left;
  }
  .tables{
    background-color: white;
    margin: 10px 0 0 0;
    padding: 10px;
  }
/*id,主键
    serial_no,机器的序列号
    brand,品牌
    model,型号
    assets_name,固定资产名称
    simple_name,名称简写
    assets_no,资产编号 保障唯一性
    assets_dep,资产所在科室 department的id
    assets_user,资产使用者
    assets_manage_dep,管理科室
    assets_company,资产提供商（以合同为准）
    use_location,使用地点
    assets_time,注册时间
    assets_reg,注册人员 userinfo的id
    scrap_time,报废时间
    scrap_user,报废回收人员 userinfo的id
    assets_type,固定资产类型 assets_type的id
    other 备注*/
</style>
